# -*- mode: ruby -*-

require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'fileutils'
require 'shlauncher'
require 'lib/version'
include FileUtils

NAME              = "<%=launcher%>"
AUTHOR            = "<%=author%>"
EMAIL             = "<%=email%>"
DESCRIPTION       = "<%=description%>"
BIN_FILES         = %w( <%=launcher%> )

VERS              = SHLAUNCHER_VER
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
CLEAN.include ['**/.*.sw?', '*.gem', '.config']

task :default do
  app = Rake.application
  app.options.show_task_pattern = Regexp.new('')
  app.display_tasks_and_comments
end

task :package => [:clean]

spec = Gem::Specification.new do |s|
	s.name              = NAME
	s.version           = VERS
	s.platform          = Gem::Platform::RUBY
	s.has_rdoc          = false
	s.summary           = DESCRIPTION
	s.description       = DESCRIPTION
	s.author            = AUTHOR
	s.email             = EMAIL
	s.executables       = BIN_FILES
	s.bindir            = "bin"
	s.require_path      = "lib"
	s.homepage          = ""
	s.rubyforge_project = ""
	#s.autorequire       = ""

	s.add_dependency('rake', '>= 0')
	s.add_dependency('shlauncher', '>= 0')
	#s.required_ruby_version = '>= 1.8.2'

	s.files = %w(README ChangeLog Rakefile) +
		Dir.glob("{bin,doc,etc,lib,script}/**/*")

end

Rake::GemPackageTask.new(spec) do |p|
	p.need_tar = true
	p.gem_spec = spec
end

task :install do
	name = "#{NAME}-#{VERS}.gem"
	sh %{rake package}
	sh %{sudo gem install pkg/#{name}}
end

task :uninstall => [:clean] do
	sh %{sudo gem uninstall #{NAME}}
end

desc 'Show information about the gem.'
task :debug_gem do
	puts spec.to_ruby
end

desc 'Update gem spec'
task :gemspec do
  open("#{NAME}.gemspec", 'w').write spec.to_ruby
end
